from django.db import models


class User(models.Model):
    """用户"""

    userid = models.AutoField(primary_key=True, verbose_name='编号')
    nickname = models.CharField(max_length=20, verbose_name='昵称')
    email = models.CharField(max_length=255, unique=True, verbose_name='邮箱')
    tel = models.CharField(max_length=20, unique=True, verbose_name='手机号码')
    locked = models.BooleanField(default=False, verbose_name='是否被禁')
    regdate = models.DateTimeField(auto_now_add=True, verbose_name='注册日期')
    credit = models.PositiveIntegerField(default=0, verbose_name='积分')

    class Meta:
        db_table = 'tb_user'
        verbose_name = '用户'
        verbose_name_plural = '用户'


class LoginLog(models.Model):
    """登录日志"""

    logid = models.AutoField(primary_key=True, verbose_name='编号')
    userid = models.IntegerField(verbose_name='用户编号')
    ipaddr = models.CharField(max_length=15, verbose_name='IP地址')
    logdate = models.DateTimeField(auto_now_add=True, verbose_name='登录日期')

    class Meta:
        db_table = 'tb_login_log'
        verbose_name = '登录日志'
        verbose_name_plural = '登录日志'


class Category(models.Model):
    """文章分类"""

    cateid = models.AutoField(primary_key=True, verbose_name='编号')
    name = models.CharField(max_length=20, verbose_name='名称')
    memo = models.CharField(default='', max_length=150, verbose_name='备注')
    total = models.PositiveIntegerField(default=0, verbose_name='文章数量')

    class Meta:
        db_table = 'tb_category'
        verbose_name = '文章分类'
        verbose_name_plural = '文章分类'


class Article(models.Model):
    """文章"""

    artid = models.AutoField(primary_key=True, verbose_name='编号')
    cateid = models.IntegerField(verbose_name='分类编号')
    userid = models.IntegerField(verbose_name='用户编号')
    title = models.CharField(max_length=50, verbose_name='标题')
    content = models.TextField(verbose_name='内容')
    pubdate = models.DateTimeField(auto_now_add=True, verbose_name='发布日期')
    lastdate = models.DateTimeField(auto_now=True, verbose_name='更新日期')
    deleted = models.BooleanField(default=False, verbose_name='是否被删除')
    withdrawn = models.BooleanField(default=False, verbose_name='是否被撤回')
    read = models.PositiveIntegerField(default=0, verbose_name='阅读量')
    good = models.PositiveIntegerField(default=0, verbose_name='点赞量')

    class Meta:
        db_table = 'tb_article'
        verbose_name = '文章'
        verbose_name_plural = '文章'


class Comment(models.Model):
    """评论"""

    comid = models.AutoField(primary_key=True, verbose_name='编号')
    pid = models.IntegerField(default=0, verbose_name='父级编号')
    userid = models.IntegerField(verbose_name='用户编号')
    artid = models.IntegerField(verbose_name='文章编号')
    content = models.CharField(max_length=250, verbose_name='内容')
    godlike = models.BooleanField(default=False, verbose_name='是否神评论')
    deleted = models.BooleanField(default=False, verbose_name='是否被删除')
    withdrawn = models.BooleanField(default=False, verbose_name='是否被撤回')
    good = models.PositiveIntegerField(default=0, verbose_name='被赞数量')
    bad = models.PositiveIntegerField(default=0, verbose_name='被踩数量')

    class Meta:
        db_table = 'tb_comment'
        verbose_name = '评论'
        verbose_name_plural = '评论'
